package com.xunhang.controller;
import com.xunhang.service.peoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/api/crawler")
public class peoController {

    private final peoService pService;

    public peoController(peoService pService) {
        this.pService = pService;
    }


    // 测试单条抓取
    @GetMapping("/peo-single")
    public String testSingle() throws IOException {
        pService.crawlSingleNews("https://news.whu.edu.cn/ljrw.htm");
        return "单条新闻抓取完成";
    }


    // 批量抓取接口
    @GetMapping("/peo-batch")
    public String batchCrawl(@RequestParam(defaultValue = "5") int count) throws IOException {
        pService.crawlBatchNews("https://news.whu.edu.cn/ljrw.htm", count);
        return "已启动批量抓取，数量: " + count;
    }

}